import loading1 from './loading1'
import loading2 from './loading2'
import loading3 from './loading3'
import loading4 from './loading4'
import loading5 from './loading5'
import loading6 from './loading6'
export default {
	/**
	 * 每个插件都有的install方法，用于安装插件
	 * @param {Object} Vue - Vue类
	 * @param {Object} [pluginOptions] - 插件安装配置
	 */
	install(Vue, options) {
		var opt = {
			container: '#app',
			defaultType: '1',
			tips: '加载中...'
		};
	  let loadArr = [];
	  let loading = [loading1,loading2,loading3,loading4,loading5,loading6];
		for(var property in options) {
			//合并默认选项
			if(options[property]) {
				opt[property] = options[property];
			}
		}
		Vue.prototype.$loading = function(type, tips) {
			var  curType = type ? type: opt.defaultType1;
			
			var  ele = "#G-loading" + curType ;
			curType = curType - 1;
			
			if(!document.querySelector(ele)) {
				const loadTpl = Vue.extend(loading[curType]);

				loadArr[curType] = new loadTpl();

				var tpl = loadArr[curType].$mount().$el;

				document.querySelector(opt.container || 'body').appendChild(tpl);
			}
			
			if(tips) {
				loadArr[curType].tips = tips;
			}
				loadArr[curType].show();
		};
		Vue.prototype.$closeloading = function(type) {
			var curType = type ? type : opt.defaultType;
				curType = curType - 1;
			loadArr[curType].hide();
		};
//		Vue.prototype.$closeAllLoad = function() {
//			for(let k of loadArr){
//					if(k){
//						k.hide();
//					}
//			}
//		}
	}
}